using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using CoreCalc.IO;

namespace CoreCalc.SheetDefinedFunctions
{
    public class ExampleSDF
    {
        //todo: load them from file, but without deleting existing content in workbook
        /// <summary>
        /// The cumulative distribution function of the Gaussian distribution N(0,1)
        /// Algorithm 66 in Statlib, based on alg. 5666 from JF Hart: Computer approximations, 1968
        /// </summary>
        public static void GaussianDistributionFunction(Workbook wb, WorkbookForm gui)
        {
            Workbook temp = Excel2003XMLReader.ReadFile("example_spreadsheets/sdf-examples.xml");
            int sheetIndex = gui.InsertSheet(true, temp[0]);

            gui.RefreshCurrentTab();

            SheetCreation.AddSDF("Gaussian" + CellAddr.ColumnName(sheetIndex), new string[] { "B6" }, sheetIndex, wb, "B7", SdfManager.MarkVersion);
            wb.Recalculate();
        }

        /// <summary>
        /// The inverse cumulative distribution function of the Gaussian distribution N(0,1)
        /// Algorithm AS241 from Applied Statistics 37, 3, 1988
        /// This agrees well with the R qnorm() function and hence seems more precise than Excel's built-in function
        /// </summary>
        /// <param name="wb"></param>
        /// <param name="gui"></param>
        public static void InverseGaussianDistributionFunction(Workbook wb, WorkbookForm gui)
        {
            Workbook temp = Excel2003XMLReader.ReadFile("example_spreadsheets/sdf-examples.xml");
            int sheetIndex = gui.InsertSheet(true, temp[0]);

            gui.RefreshCurrentTab();

            SheetCreation.AddSDF("InvGaussian" + CellAddr.ColumnName(sheetIndex), new string[] { "B27" }, sheetIndex, wb, "B28", SdfManager.MarkVersion);
            wb.Recalculate();
        }
    }
}
